package com.og.backingbean;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.NotEmpty;

/**
 * @author Renaud DIANA
 *
 */
@Entity
@NamedQueries({@NamedQuery(name = "Person.findAll", query = "SELECT p FROM Person p ORDER BY p.idPerson ASC"),
	@NamedQuery(name = "Person.findByCompany", query = "SELECT p FROM Person p WHERE p.company.idCompany = :idCompany ORDER BY p.idPerson ASC")})
public class Person implements Serializable{

	private static final long serialVersionUID = 1L;
		
	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
	private int idPerson;	
	@Size(max = 15)
	@Column(length = 15)
	private String title;
	@NotNull
	@NotEmpty
	@Size(max = 50)
	@Column(nullable = false, length = 50)
	private String lastName;
	@Size(max = 50)
	@Column(length = 50)
	private String firstName;
	@Size(max = 20)
	@Column(length = 20)
	private String phone;
	@Size(max = 20)
	@Column(length = 20)
	private String gsm;	
	@NotNull
	@NotEmpty
	@Size(max = 50)
	@Column(nullable = false, length = 50)
	private String email;
	@Size(max = 50)
	@Column(length = 50)
	private String email2;	
	private String comments;
	@ManyToOne
	@JoinColumn(nullable = false)
	private Company company;
	@OneToMany(mappedBy = "person", cascade = CascadeType.ALL)
	@JoinColumn(name = "person_idperson")	
	private List<TimeSheet> listTimeSheet;
		
	/**
	 * default constructor
	 */
	public Person() {
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + idPerson;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Person other = (Person) obj;
		if (idPerson != other.idPerson)
			return false;
		return true;
	}

	public int getIdPerson() {
		return idPerson;
	}

	public void setIdPerson(int idPerson) {
		this.idPerson = idPerson;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getGsm() {
		return gsm;
	}

	public void setGsm(String gsm) {
		this.gsm = gsm;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getEmail2() {
		return email2;
	}

	public void setEmail2(String email2) {
		this.email2 = email2;
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

	public List<TimeSheet> getListTimeSheet() {
		return listTimeSheet;
	}

	public void setListTimeSheet(List<TimeSheet> listTimeSheet) {
		this.listTimeSheet = listTimeSheet;
	}	
}